<template>
  <view>
    <!-- 图片开始 -->
    <view class="album_bg">
      <image :src="album.cover" mode="widthFix" />
      <view class="album_info">
        <view class="album_name">{{album.name}}</view>
        <view class="album_btn">关注专辑</view>
      </view>
    </view>
    <!-- 图片结束 -->

    <!-- 专辑作者开始  -->
    <view class="album_detail">
      <view class="author_info">
        <image :src="album.user.avatar" mode="widthFix" />
        <view class="author_name">{{album.user.name}}</view>
      </view>
      <view class="album_desc">
        <text>{{album.desc}}</text>
      </view>
    </view>
    <!-- 专辑作者结束  -->

    <!-- 列表开始 -->
    <view class="album_list">
      <view class="album_item" v-for="(item,index) in wallpaper" :key="item.id">
        <go-detail :list="wallpaper" :index="index">
          <image :src="item.thumb+item.rule.replace('$<Height>',360)" mode="widthFix" />
        </go-detail>
      </view>
    </view>
    <!-- 列表结束 -->
  </view>
</template>

<script>
import goDetail from "@/component/goDetail";
export default {
  components:{goDetail},
  data() {
    return {
      id: -1,
      params: {
        limit: 30,
        order: "new",
        skip: 0,
        first: 1
      },
      album: {},
      wallpaper: [],
      hasMore: true
    };
  },
  methods: {
    getList() {
      this.request({
        url: `http://157.122.54.189:9088/image/v1/wallpaper/album/${this.id}/wallpaper`,
        data: this.params
      }).then(res => {
        //console.log(res.res);
        if (res.res.wallpaper.length === 0) {
          this.hasMore = false;
          uni.showToast({
            title: "没有更多数据了!",
            icon: "none"
          });
          return;
        }

        if (Object.keys(this.album).length === 0) {
          this.album = res.res.album;
        }
        this.wallpaper = [...this.wallpaper, ...res.res.wallpaper];
      });
    }
  },
  onLoad(option) {
    this.id = option.id;
    // this.id = "5e59075ae7bce73965512bd6";
    // this.id = "5d5f8e45e7bce75ae7fb8278";
    this.id = option.id;
    this.getList();
  },
  onReachBottom() {
    if (this.hasMore) {
      this.params.first = 0;
      this.params.skip += this.params.limit;
      this.getList();
    } else {
      uni.showToast({
        title: "没有更多数据了!",
        icon: "none"
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.album_bg {
  position: relative;

  .album_info {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 80rpx;
    padding: 0 15rpx;
    color: #fff;

    .album_name {
      font-size: 40rpx;
    }
    .album_btn {
      background-color: $color;
      font-size: 30rpx;
      width: 152rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-content: center;
      border-radius: 10rpx;
    }
  }
}

.album_detail {
  padding: 10rpx;
  .author_info {
    padding: 10rpx 0;
    display: flex;
    image {
      width: 50rpx;
    }
    .author_name {
      color: #000;
      margin-left: 15rpx;
    }
  }
  .album_desc {
  }
}

.album_list {
  display: flex;
  flex-wrap: wrap;
  .album_item {
    width: 33.33%;
    border: 3rpx solid #fff;
    border-radius: 10rpx;
    image {
    }
  }
}
</style>